package com.xuecheng.content.api;

import com.xuecheng.content.model.dto.BindTeachplanMediaDto;
import com.xuecheng.content.model.dto.SaveTeachplanDto;
import com.xuecheng.content.model.vo.TeachplanVo;
import com.xuecheng.content.service.TeachplanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/teachplan")
@Api(value = "课程计划编辑接口",tags = "课程计划编辑接口")
public class TeachplanController {

    @Autowired
    private TeachplanService teachplanService;

    /**
     * 查询课程计划
     * @param courseId
     * @return
     */
    @GetMapping("/{courseId}/tree-nodes")
    @ApiOperation("查询课程计划树形结构")
    public List<TeachplanVo> getTreeNodes(@PathVariable Long courseId) {
        List<TeachplanVo> teachplanTree = teachplanService.findTeachplanTree(courseId);
        return teachplanTree;
    }

    @PostMapping
    @ApiOperation("课程计划创建或修改")
    public void saveTeachplan(@RequestBody SaveTeachplanDto saveTeachplanDto) {
        teachplanService.saveTeachplan(saveTeachplanDto);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除课程计划")
    public void deleteTeachplan(@PathVariable Long id) {
        teachplanService.deleteTeachplan(id);
    }

    @PostMapping("/{move}/{id}")
    @ApiOperation("移动课程计划排序")
    public void moveTeachplan(@PathVariable("id") Long id,@PathVariable("move") String move) {
        teachplanService.moveTeachplan(move, id);
    }

    @PostMapping("/association/media")
    @ApiOperation("课程计划和媒资信息绑定")
    public void associationMedia(@RequestBody BindTeachplanMediaDto bindTeachplanMediaDto){
        teachplanService.associationMedia(bindTeachplanMediaDto);
    }

    @DeleteMapping("/association/media/{teachplanId}/{mediaId}")
    @ApiOperation("课程计划和媒资信息解除绑定")
    public void unboundMedia(@PathVariable("teachplanId") String teachplanId,@PathVariable("mediaId") String mediaId){
        teachplanService.unboundMedia(teachplanId, mediaId);
    }
}
